<?php

namespace Site\HomeBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class DefaultController extends Controller
{
    /**
     * @Route("/")
     */
    public function indexAction()
    {
        return $this->render('SiteHomeBundle:Default:index.html.twig');
    }

   	protected function getArticles()
   	{
   		return array(
   			array('title'=>'测试文章1', 'id'=>1, 'content'=>'测试文章内容1'),
   			array('title'=>'测试文章2', 'id'=>2,'content'=>'测试文章内容2')
   		);
   	}
    /**
     * @Route("/list")
     */
    public function listAction()
    {
    	$data = array('articles' => $this->getArticles());
    	return $this->render('SiteHomeBundle:Default:list.html.twig', $data);
    }	

    /**
 	* @Route("/show/{id}", name="site_home_show", requirements={"id" = "\d+"}, defaults={"id" = 1})
 	*/
    public function showAction($id)
    {
    	$articles = $this->getArticles();
    	$article = array();
    	foreach ($articles as $key => $value) {
    		if ($value['id'] == $id) {
    			$article = $value;
    		}
    	}
    	$data = array('article'=>$article);
    	return $this->render('SiteHomeBundle:Default:show.html.twig', $data);
    }
}
